What is decamelize?
The decamelize npm package is used to convert a string from camelCase to a lower case string with a custom separator (defaulting to an underscore). It is useful for transforming variable names or keys in objects from camelCase to a format that is more common in other languages or contexts, such as snake_case for database fields or kebab-case for CSS class names.
What are decamelize's main functionalities?
Decamelize a string
Converts 'myCamelCaseString' to 'my_camel_case_string' using the default separator.
"myCamelCaseString".decamelize()
Decamelize with a custom separator
Converts 'myCamelCaseString' to 'my-camel-case-string' using a custom separator ('-').
"myCamelCaseString".decamelize('-')
Preserve consecutive uppercase characters
Converts 'myURLString' to 'my_url_string', preserving the consecutive uppercase characters.
"myURLString".decamelize('_', { preserveConsecutiveUppercase: true })
Other packages similar to decamelize
snake-case
The snake-case package converts strings to snake_case. It is similar to decamelize but is specifically tailored to produce snake_case without providing options for custom separators.
kebab-case
The kebab-case package is designed to convert strings to kebab-case. While it serves a similar purpose in changing the case of strings, it is focused on kebab-case rather than providing a customizable separator.
change-case
The change-case package is a more comprehensive string transformation library that includes a variety of case conversion functions, including decamelize. It offers a broader set of functionalities compared to the single-purpose decamelize package.
decamelize
Convert a camelized string into a lowercased one with a custom separator
Example: unicornRainbow
→ unicorn_rainbow
Install
$ npm install decamelize
Usage
const decamelize = require('decamelize');
decamelize('unicornRainbow');
decamelize('unicornRainbow', '-');
API
decamelize(input, [separator])
input
Type: string
separator
Type: string
Default: _
Related
See camelcase
for the inverse.
License
MIT © Sindre Sorhus